package com.tutk.AV_Player;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;


public class VideoCall extends AppCompatActivity implements SurfaceHolder.Callback {
//    static final String UID = "D376CM8LR31XJ8NN111A";
    static final String UID = "ERPAA154KFVWTNPGUHCJ";

    private VideoPlayer mPlayer = null;
    private AudioPlayer aPlayer = null;
    private SurfaceView surfaceView;
    private SurfaceHolder holder;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//            setContentView(R.layout.activity_main);
//        surfaceView = (SurfaceView) findViewById(R.id.id_sv);
//        aCache = ACache.get(getApplicationContext());
            (new Thread() {
                public void run() {
                    Log.w("print", "UID = " + UID);
                    Client.start(VideoCall.UID);
                }
            }).start();
        surfaceView = new SurfaceView(this);

        holder = surfaceView.getHolder();
        holder.setFixedSize(1280, 720);
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        // 为SurfaceHolder添加回调
        holder.addCallback(this);
        setContentView(surfaceView);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        if (mPlayer == null) {
            mPlayer = new VideoPlayer(holder.getSurface());
            mPlayer.start();
//            aPlayer = new AudioPlayer();
//            aPlayer.start();
        }
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        if (mPlayer != null) {
            mPlayer.interrupt();
//            aPlayer.interrupt();
        }
    }

}
